﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Trans.trans;

namespace Trans.car
{
    public partial class Add_accident : Form
    {
        private DataRowView row;
        public Add_accident()
        {
            InitializeComponent();
        }

        private void Add_accident_Load(object sender, EventArgs e)
        {
            row = (DataRowView)tbaccidentBindingSource.AddNew();
        }

        private void bt_add_Click(object sender, EventArgs e)
        {
            if (this.ValidateChildren())
            {
                try
                {
                    row["oper_id"] = session.Oper.id;
                    tbaccidentBindingSource.EndEdit();
                    tb_accidentTableAdapter.Update(dataSet.tb_accident);
                    this.Close();
                    MessageBox.Show("添加成功", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show("出错啦" + ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }

        private void bt_cancel_Click(object sender, EventArgs e)
        {
            tbaccidentBindingSource.CancelEdit();
            this.Close();
        }

        

        private void tx_place_Validating(object sender, CancelEventArgs e)
        {
            if(tx_place.Text.Length>0)
            {
                error.SetError(tx_place, "");
            }
            else
            {
                error.SetError(tx_place, "请填写出错地点");
                e.Cancel = true;
            }
        }
    }
}
